/*
 * Flashbox4SettingContainer.cpp
 *
 *  Created on: 2009-1-20
 *      Author: hequn
 */

#include <coemain.h>
#include <EIKENV.H>
#include "Flashbox4SettingContainer.h"
#include <stringloader.h>
#include "ConstDefined.hrh"
#include "FbListData.h"
#include "Flashbox4.hrh"
#include "flashbox4.mbg"
#include "flashbox4_setting.mbg"
#include "Flashbox4_0x20021B21.rsg"
#include "FlashboxServerSession.h"
//#include "Jpg2Bitmap.h"

#include "FbUtils.h"
#include <BAUTILS.H>

CFlashbox4SettingContainer::~CFlashbox4SettingContainer ()
{
	delete m_pAppLogoBmp;

	delete m_pCategoryBarSelBmp;
	delete m_pTurnOnOrOffSelBmp;

	delete m_pSoftKeyBar;

	for (TInt i = 0; i < 2; i++ )
	{
		delete buf_SettingSubTitle[i];
		delete m_pTabImgArray[i];
		delete m_pTabImgMaskArray[i];
		delete m_pFileSelectTitle[i];
	}
	delete buf_SettingItemSwitch;
	delete buf_SettingDescript;
	delete buf_SettingTitle;
	delete m_pFileList;
	delete m_pXmlHandler;
	delete m_pFileImage;
}

void CFlashbox4SettingContainer::ConstructL (const TRect& aRect, TUid aLastViewID, TInt aActiveTabIndex )
{
	CreateWindowL ();
	iLastViewID = aLastViewID.iUid;
	iActiveMainIndex = aActiveTabIndex;

	iSetItembackFocus = 0;
	iCurrentTabId = 0;	
	
	if(aActiveTabIndex == 2)
		iCurrentTabId = 1;
	//m_pXmlHandler
	m_pXmlHandler = CXmlHandler::NewL (*this );
	//内容列表
	TRect listRect (aRect.iTl.iX + 1, aRect.iTl.iY, aRect.iBr.iX,
			aRect.iBr.iY - KFbSoftKeyRect.Height ()- 5 );
	m_pFileList = CFbList::NewL (listRect, this );
	m_pFileList->SetBackground (KFbSettingTopRect1Color,
			KFbSettingTopRect1Color );
	m_pFileList->SetFocusedBackground (KFbFocusRectColor, -1 );
	m_pFileList->SetObserver (this );
	m_pFileList->MakeVisible (EFalse );

	//初始化Control
	InitializeControl ();

	SetRect (aRect );
	//全屏显示
	//SetExtentToWholeScreen();
	ActivateL ();
}

void CFlashbox4SettingContainer::Draw (const TRect& /*aRect*/) const
{
	CWindowGc& gc = SystemGc ();
	
	TRect drawRect (Rect () );
	
	//---------Flush the background color------<Begin>//
	gc.SetPenStyle (CGraphicsContext::ENullPen );
	gc.SetBrushColor (KFbTabgroupTopColor );
	gc.SetBrushStyle (CGraphicsContext::ESolidBrush );
	gc.DrawRect (drawRect );
	//---------Flush the background color------<End>//

	//---------Draw the title and subtitle and body rect----<Begin>//
	TRect contentRect (0, 50, 240, 295 );
	TRect RoundRect (9, 70, 231, 258 );
	
	gc.SetBrushColor (KFbSettingTopRect1Color );
	gc.DrawRect (contentRect );
	//---------Draw the title and subtitle rect----<End>//
	if (m_pAppLogoBmp ) //-----Draw lefttop logo!
	{
		gc.DrawBitmap (KFbAppLogoRect, m_pAppLogoBmp );
	}
	//-------Ready for draw Setting Title and SubTitle Text!------//	
	CFont* font = NULL;//iCoeEnv->NormalFont();
	TFontSpec fontsp = iCoeEnv->NormalFont ()->FontSpecInTwips ();
	
	TInt font_oHeight = fontsp.iHeight;
	fontsp.iHeight = 7 * font_oHeight / 10;
	iCoeEnv->ScreenDevice ()->GetNearestFontInTwips (font, fontsp );
	if (font )
		gc.UseFont (font );
	else
		gc.UseFont (iCoeEnv->NormalFont () );
	
	//Draw Setting page Title!
	gc.SetPenColor (KFbSettingTitleTextColor );
	gc.SetPenStyle (CGraphicsContext::ESolidPen );
	gc.DrawText (*buf_SettingTitle, KFbSettingTitlePoint );
	
	if (m_pFileList && m_pFileList->IsVisible() )//文件选择状态(2级页面)e
	{
		gc.SetBrushColor (KFbSettingTopRect2Color );
		gc.DrawRect(KFbSettingTitleRect);
		gc.DrawText(*m_pFileSelectTitle[iCurrentTabId], KFbSettingTitleRect, 
				KFbSettingTitleRect.Height() - 3);
	}
	else//普通状态(1级页面)
	{
		gc.SetPenStyle (CGraphicsContext::ENullPen );
		if (iCurrentTabId == 0 )
		{
			gc.DrawRect (KFbSettingTopRect1 );
			gc.SetBrushColor (KFbSettingTopRect2Color );
			gc.DrawRect (KFbSettingTopRect2 );
		}
		else
			if (iCurrentTabId == 1 )
			{
				gc.DrawRect (KFbSettingTopRect2 );
				gc.SetBrushColor (KFbSettingTopRect2Color );
				gc.DrawRect (KFbSettingTopRect1 );
			}

		gc.SetPenColor (KFbSettingRoundRectBorderColor );
		gc.SetPenStyle (CGraphicsContext::ESolidPen );
		gc.SetBrushColor (KFbSettingRoundRectColor );
		TRect RoundRect2(RoundRect.iTl.iX - 2, RoundRect.iTl.iY - 2,
				RoundRect.iBr.iX + 2, RoundRect.iBr.iY + 2);
		gc.DrawRoundRect (RoundRect2, TSize (8, 8 ) );
		gc.DrawRoundRect (RoundRect, TSize (8, 8 ) );
		gc.SetPenStyle (CGraphicsContext::ENullPen );

		//---------Paint Selected Item background color-------//
		gc.SetBrushColor (KFbSettingSelectedRectColor );
		gc.DrawRect (TRect (KFbSetItembackRect[iSetItembackFocus].iTl.iX - 5,
				KFbSetItembackRect[iSetItembackFocus].iTl.iY - 3,
				KFbSetItembackRect[iSetItembackFocus].iBr.iX + 5,
				KFbSetItembackRect[iSetItembackFocus].iBr.iY + 3 ) );

		if (m_pCategoryBarSelBmp )
		{
			gc.DrawBitmap (KFbSetItembackRect[0], m_pCategoryBarSelBmp );
		}

		if (m_pTurnOnOrOffSelBmp )
		{
			gc.DrawBitmap (KFbSetItembackRect[1], m_pTurnOnOrOffSelBmp );
		}

		if (m_pTabImgArray[0] && m_pTabImgMaskArray[0] )
		{
			gc.DrawBitmapMasked (TRect (45, 30, 70, 50 ), m_pTabImgArray[0],
					m_pTabImgArray[0]->SizeInPixels (), m_pTabImgMaskArray[0],
					EFalse );
		}
		if (m_pTabImgArray[1] && m_pTabImgMaskArray[1] )
		{
			gc.DrawBitmapMasked (TRect (145, 30, 170, 50 ), m_pTabImgArray[1],
					m_pTabImgArray[1]->SizeInPixels (), m_pTabImgMaskArray[1],
					EFalse );
		}

		

		//gc.SetPenColor(KRgbRed);
		//File name
		TFileName fileName;
		iCurrentTabId == 0 ? fileName =  GetAppUi()->m_pSettingPingbao->m_FileName 
				: fileName = GetAppUi()->m_pSettingLaidian->m_FileName;
		if(fileName.Length() > 0)
		{
			if (!iSetItembackFocus )
				gc.SetPenColor (KRgbBlack);
			else
				gc.SetPenColor (KRgbWhite);
		
			gc.DrawText(fileName, KFbSettingItemsFileNamePoint);
		}
		
		if (iSetItembackFocus )
			gc.SetPenColor (KRgbBlack);
		else
			gc.SetPenColor (KRgbWhite);
		//descript
		gc.DrawText (*buf_SettingDescript, TPoint (
				KFbSettingItemsSwitchPoint.iX - 135,
				KFbSettingItemsSwitchPoint.iY ) );
		//switch
		gc.DrawText (*buf_SettingItemSwitch, KFbSettingItemsSwitchPoint );
		
		//Draw SubTitle!
		iCurrentTabId == 0 ? gc.SetPenColor (TRgb (21, 41, 74 ) )
						: gc.SetPenColor (TRgb (192, 226, 251 ) );
		gc.DrawText (*buf_SettingSubTitle[0], KFbSettingSubTitlePoint[0] );
		iCurrentTabId == 1 ? gc.SetPenColor (TRgb (21, 41, 74 ) )
								: gc.SetPenColor (TRgb (192, 226, 251 ) );
		gc.DrawText (*buf_SettingSubTitle[1], KFbSettingSubTitlePoint[1] );
		
		//画文件图标
		if(m_pFileImage && m_pFileImage->GetBitmap())
		{
			gc.DrawBitmap(TRect(40,80, 90,130), m_pFileImage->GetBitmap());
		}
		
	}
	gc.DiscardFont ();
	iCoeEnv->ScreenDevice ()->ReleaseFont (font );
}

CCoeControl* CFlashbox4SettingContainer::ComponentControl (TInt aIndex ) const
{
	
	switch (aIndex )
	{
	case 0:
		return m_pSoftKeyBar;
	case 1:
		return m_pFileList;
	default:
		return NULL;
	}
}

TInt CFlashbox4SettingContainer::CountComponentControls () const
{
	return 2;
}

void CFlashbox4SettingContainer::SizeChanged ()
{
	DrawNow ();
}

void CFlashbox4SettingContainer::InitializeControl ()
{
	TFileName fileIcon;
	if (iCurrentTabId == 0 )
	{
		iItemsSetValue = (TInt8) GetAppUi()->m_pSettingPingbao->m_isOn;
		fileIcon = GetAppUi()->m_pSettingPingbao->m_IconPath;
	}
	else
	{
		iItemsSetValue = (TInt8) GetAppUi()->m_pSettingLaidian->m_isOn;
		fileIcon = GetAppUi()->m_pSettingLaidian->m_IconPath;
	}
	UpdateFileIcon(fileIcon);
	
	m_pAppLogoBmp = (CEikonEnv::Static ())->CreateBitmapL (KFlashboxImagePath,
			EMbmFlashbox4Applogo );

	//Initial the bmp and focus for SetItemback!
	LoadContentBmpResourceL (ECategorySelBar );
	LoadContentBmpResourceL (ETurnOffUnSelBar + (iItemsSetValue == EItemsOn ? 2
			: 0) );

	m_pTabImgArray[0] = (CEikonEnv::Static ())->CreateBitmapL (
			KFlashboxImagePath, EMbmFlashbox4Tabpingbao );
	m_pTabImgArray[1] = (CEikonEnv::Static ())->CreateBitmapL (
			KFlashboxImagePath, EMbmFlashbox4Tablaidian );
	m_pTabImgMaskArray[0] = (CEikonEnv::Static ())->CreateBitmapL (
			KFlashboxImagePath, EMbmFlashbox4Tabpingbao_mask );
	m_pTabImgMaskArray[1] = (CEikonEnv::Static ())->CreateBitmapL (
			KFlashboxImagePath, EMbmFlashbox4Tablaidian_mask );

	m_pFileSelectTitle[0] = StringLoader::LoadL (R_SETTING_SELECTPINGBAO );
	m_pFileSelectTitle[1] = StringLoader::LoadL (R_SETTING_SELECTLAIDIAN );
	buf_SettingDescript = StringLoader::LoadL (R_SETTING_DESCRIPT );

	//Initial and Set the SoftKeyBar Content!
	m_pSoftKeyBar = CFbSoftKeyBar::NewL (KFbSoftKeyRect, this, this );

	m_pSoftKeyBar->SetLeftKeyL (EMainContainerKeyConfirm, R_SOFT_KEY_CONFIRM );
	m_pSoftKeyBar->SetRightKeyL (EMainContainerKeyCancel, R_SOFT_KEY_CANCEL);

	//Initial Text
	LoadTextResourceL (ETextTitleR );
	LoadTextResourceL (ETextItemsR );
	
	LoadTextResourceL (ETextSwitchR );
}

void CFlashbox4SettingContainer::LoadContentBmpResourceL (const TInt &aSourceId )
{
	switch (aSourceId )
	{
	case ECategorySelBar:
		if (m_pCategoryBarSelBmp )
		{
			delete m_pCategoryBarSelBmp;
		}
		m_pCategoryBarSelBmp = (CEikonEnv::Static ())->CreateBitmapL (
				KFlashboxSettingImagePath,
				EMbmFlashbox4_settingSet_categorybar_sel );
		break;
	case ECategoryUnSelBar:
		if (m_pCategoryBarSelBmp )
		{
			delete m_pCategoryBarSelBmp;
		}
		m_pCategoryBarSelBmp = (CEikonEnv::Static ())->CreateBitmapL (
				KFlashboxSettingImagePath,
				EMbmFlashbox4_settingSet_categorybar_unsel );
		break;
	case ETurnOffSelBar:
		if (m_pTurnOnOrOffSelBmp )
		{
			delete m_pTurnOnOrOffSelBmp;
		}
		m_pTurnOnOrOffSelBmp = (CEikonEnv::Static ())->CreateBitmapL (
				KFlashboxSettingImagePath,
				EMbmFlashbox4_settingSet_turnoffbar_sel );
		break;
	case ETurnOffUnSelBar:
		if (m_pTurnOnOrOffSelBmp )
		{
			delete m_pTurnOnOrOffSelBmp;
		}
		m_pTurnOnOrOffSelBmp = (CEikonEnv::Static ())->CreateBitmapL (
				KFlashboxSettingImagePath,
				EMbmFlashbox4_settingSet_turnoffbar_unsel );
		break;
	case ETurnOnSelBar:
		if (m_pTurnOnOrOffSelBmp )
		{
			delete m_pTurnOnOrOffSelBmp;
		}
		m_pTurnOnOrOffSelBmp = (CEikonEnv::Static ())->CreateBitmapL (
				KFlashboxSettingImagePath,
				EMbmFlashbox4_settingSet_turnonbar_sel );
		break;
	case ETurnOnUnSelBar:
		if (m_pTurnOnOrOffSelBmp )
		{
			delete m_pTurnOnOrOffSelBmp;
		}
		m_pTurnOnOrOffSelBmp = (CEikonEnv::Static ())->CreateBitmapL (
				KFlashboxSettingImagePath,
				EMbmFlashbox4_settingSet_turnonbar_unsel );
		break;
	case EProductSelBar:
		break;
	case EProductUnSelBar:
		break;
	default:
		break;
	}
}

void CFlashbox4SettingContainer::SoftKeyEvent (TInt aKeyId )
{
	switch (aKeyId )
	//Handle anythings! need modify
	{
	case EMainContainerKeyConfirm:
		SaveConfigL ();
		GetAppUi ()->ActiveViewL (iLastViewID, iActiveMainIndex );
		break;
		
	case EMainContainerKeyCancel:
		if(m_pFileList->IsVisible())
		{
			m_pSoftKeyBar->SetLeftKeyL (EMainContainerKeyConfirm, R_SOFT_KEY_CONFIRM );
			m_pFileList->MakeVisible(EFalse);
			DrawNow();
		}
		else
			GetAppUi ()->ActiveViewL (iLastViewID, iActiveMainIndex );
		break;
	case EMainContainerKeySelect:
		UpdateSelectedFile(m_pFileList,m_pFileList->GetFocusedIndex());
		m_pSoftKeyBar->SetLeftKeyL (EMainContainerKeyConfirm, R_SOFT_KEY_CONFIRM );
		m_pFileList->MakeVisible(EFalse);
		DrawNow();
		break;
	default:
		break;
	}
}

void CFlashbox4SettingContainer::LoadTextResourceL (ETextResource aRID )
{
	switch (aRID )
	{
	case ETextTitleR:
		if (buf_SettingTitle )
		{
			delete buf_SettingTitle;
		}
		buf_SettingTitle = StringLoader::LoadL (R_SETTING_TITLE);
		break;
		
	case ETextItemsR:
		for (TInt i = 0; i < 2; i++ )
		{
			if (buf_SettingSubTitle[i] )
			{
				delete buf_SettingSubTitle[i];
			}
			buf_SettingSubTitle[i] = StringLoader::LoadL (R_TAB_ITEM_TEXT2 + i );
		}
		break;
		
	case ETextSwitchR:
		if (buf_SettingItemSwitch )
		{
			delete buf_SettingItemSwitch;
		}
		buf_SettingItemSwitch = StringLoader::LoadL (R_SETTING_OFF
		+ iItemsSetValue );
		break;
	};
}


//from MXmlHandlerObserver
void CFlashbox4SettingContainer::OnXmlNodeParseCompletedL (TInt aError, CXmlNode *pDataNode, TInt/* aSession*/)
{
	//
	if (pDataNode == NULL )
		return;

	TInt selectedFileId = 0;
	if (iCurrentTabId == 0 )
	{
		selectedFileId = (TInt) GetAppUi()->m_pSettingPingbao->m_fileId;
	}
	else
	{
		selectedFileId = (TInt) GetAppUi()->m_pSettingLaidian->m_fileId;
	}
	CleanupStack::PushL (m_pFileList );
	TInt childCount = pDataNode->ChildCount ();
	for (TInt i = 0; i < childCount; i++ )
	{
		CXmlNode *pItemNode = pDataNode->ChildNode (i );
		if (pItemNode )
		{
			CXmlNode *pIdNode = pItemNode->ChildNode (_L8("id"));
			TInt nodeId = pIdNode ? String2Int (*pIdNode->i_pValue ) : 0;
			
			//数据节点
			CFbListData *pListItem = new (ELeave) CFbListData (nodeId );
			CleanupStack::PushL (pListItem );
			pListItem->m_pDataBlock = pItemNode->AllocL ();

			CXmlNode *pNameNode = pItemNode->ChildNode (_L8("name"));
			CXmlNode *pDesc = pItemNode->ChildNode (_L8("desc"));
			if (pDesc && pDesc->i_pValue )
				pListItem->ConstructL (*pNameNode->i_pValue, *pDesc->i_pValue );
			else
				pListItem->ConstructL (*pNameNode->i_pValue );

			CFbsBitmap *pIcon;
			if (selectedFileId == nodeId )
			{
				pIcon = (CEikonEnv::Static ())->CreateBitmapL (
						KFlashboxSettingImagePath,
						EMbmFlashbox4_settingSet_product_sel );
			}
			else
			{
				pIcon = (CEikonEnv::Static ())->CreateBitmapL (
						KFlashboxSettingImagePath,
						EMbmFlashbox4_settingSet_product_unsel );
			}
			CFbsBitmap *pIconB = (CEikonEnv::Static ())->CreateBitmapL (
					KFlashboxImagePath, EMbmFlashbox4Applogo );
			
			CXmlNode *pUrl = pItemNode->ChildNode (_L8("iconurl"));
			if (pUrl && pUrl->i_pValue )
				pListItem->SetIconUrl (*pUrl->i_pValue );
			pListItem->SetItemIcons (pIcon, pIconB );
			pListItem->SetDataStoreType (ETypeLocal );
			//生成list项
			m_pFileList->AddItemL (pListItem );
			CleanupStack::Pop ();//pListItem		
		}
	}
	m_pFileList->UpdatePageSatuse ();
	m_pFileList->DrawNow ();
	
	CleanupStack::Pop ();//
}

//from MListObserver
/**
 * pHandle 发出消息的对象
 * aItemIndex:激活的item 序号
 * aItemID : 激活的item id
 * aEventType:事件类型
 */
void CFlashbox4SettingContainer::ListItemEvent (CFbList *pHandle, TInt aItemIndex, TInt /*aItemID*/, TInt aEventType )
{
	if(pHandle == m_pFileList)
	{
		switch(aEventType)
		{
		case EItemSelected:
			UpdateSelectedFile(pHandle,aItemIndex);
			m_pSoftKeyBar->SetLeftKeyL (EMainContainerKeyConfirm, R_SOFT_KEY_CONFIRM );
			m_pFileList->MakeVisible(EFalse);
			DrawNow();
			break;
		}
	}
}

void CFlashbox4SettingContainer::UpdateSelectedFile(CFbList* pHandle, TInt aItemIndex)
{
	CFbListData *pData = pHandle->GetListItem(aItemIndex);
	if(!pData)
		return;
	if(iCurrentTabId == 0)
	{
		GetAppUi()->m_pSettingPingbao->m_fileId = pData->GetItemId();
		GetAppUi()->m_pSettingPingbao->m_FileName.Copy(*pData->GetTitle());
		GetAppUi()->m_pSettingPingbao->m_IconPath.Copy(*pData->m_pIconUrl);
		GetAppUi()->m_pSettingPingbao->m_FilePath.Copy(KFbContentsPath);
		AddDrive(GetAppUi()->m_pSettingPingbao->m_FilePath);
		GetAppUi()->m_pSettingPingbao->m_FilePath.AppendFormat(_L("\\data\\394\\%d.swf"), GetAppUi()->m_pSettingPingbao->m_fileId);
		UpdateFileIcon(GetAppUi()->m_pSettingPingbao->m_IconPath);
	}
	else
	{
		GetAppUi()->m_pSettingLaidian->m_fileId = pData->GetItemId();
		GetAppUi()->m_pSettingLaidian->m_FileName.Copy (*pData->GetTitle () );
		GetAppUi()->m_pSettingLaidian->m_IconPath.Copy (*pData->m_pIconUrl );
		GetAppUi()->m_pSettingLaidian->m_FilePath.Copy (KFbContentsPath );
		AddDrive(GetAppUi()->m_pSettingLaidian->m_FilePath);
		GetAppUi()->m_pSettingLaidian->m_FilePath.AppendFormat (_L("\\data\\395\\%d.swf"), GetAppUi()->m_pSettingLaidian->m_fileId );
		UpdateFileIcon(GetAppUi()->m_pSettingLaidian->m_IconPath);
	}	
}

void CFlashbox4SettingContainer::UpdateFileIcon(const TDesC &aIconPath)
{
	if(m_pFileImage)
	{
		delete m_pFileImage;
		m_pFileImage = NULL;
	}
	m_pFileImage = new (ELeave) CMulImage(this);
	m_pFileImage->OpenFileL(aIconPath);
}

void CFlashbox4SettingContainer::MulImageReady (CMulImage *pImage )
{
	if(pImage->GetBitmap())
		DrawNow();
}

/*
 * 
 */
TKeyResponse CFlashbox4SettingContainer::OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType )
{
	//1.响应左右软键
	if (m_pSoftKeyBar )
	{
		TKeyResponse keyRes = m_pSoftKeyBar->OfferKeyEventL (aKeyEvent, aType );
		if (keyRes == EKeyWasConsumed )
			return keyRes;
	}

	if (m_pFileList && m_pFileList->IsVisible () )
	{
		return m_pFileList->OfferKeyEventL (aKeyEvent, aType );
	}

	switch (aKeyEvent.iCode )
	{
	case EKeyUpArrow:
	case EKeyDownArrow:
		iSetItembackFocus == 0 ? iSetItembackFocus = 1 : iSetItembackFocus = 0;
		if (iSetItembackFocus )
		{
			LoadContentBmpResourceL (ECategoryUnSelBar );
			LoadContentBmpResourceL (ETurnOffSelBar + (iItemsSetValue
					== EItemsOn ? 2 : 0) );
		}
		else
		{
			LoadContentBmpResourceL (ECategorySelBar );
			LoadContentBmpResourceL (ETurnOffUnSelBar + (iItemsSetValue
					== EItemsOn ? 2 : 0) );
		}
		break;
		
	case EKeyLeftArrow:
	case EKeyRightArrow:
		iCurrentTabId == 0 ? iCurrentTabId = 1 : iCurrentTabId = 0;
		if (iCurrentTabId == 0 )
		{
			iItemsSetValue = (TInt8) GetAppUi()->m_pSettingPingbao->m_isOn;
			UpdateFileIcon(GetAppUi()->m_pSettingPingbao->m_IconPath);
		}
		else
		{
			iItemsSetValue = (TInt8) GetAppUi()->m_pSettingLaidian->m_isOn;
			UpdateFileIcon(GetAppUi()->m_pSettingLaidian->m_IconPath);
		}
		LoadTextResourceL (ETextSwitchR );
		if (iSetItembackFocus )
			LoadContentBmpResourceL (ETurnOffSelBar + (iItemsSetValue
				== EItemsOn ? 2 : 0) );
		else
			LoadContentBmpResourceL (ETurnOffUnSelBar + (iItemsSetValue
				== EItemsOn ? 2 : 0) );
		break;
	case EKeyDevice3:
		if (iSetItembackFocus == 1 )//改变设置状态
		{
			iItemsSetValue == EItemsOn ? iItemsSetValue = EItemsOff
					: iItemsSetValue = EItemsOn;
			LoadTextResourceL (ETextSwitchR );
			LoadContentBmpResourceL (ETurnOffSelBar + (iItemsSetValue
					== EItemsOn ? 2 : 0) );
			if (iCurrentTabId == 0 )//pingbao
			{
				GetAppUi()->m_pSettingPingbao->m_isOn = (TBool) iItemsSetValue;
			}
			else//laidian
			{
				GetAppUi()->m_pSettingLaidian->m_isOn = (TBool) iItemsSetValue;
			}
		}
		else
			if (iSetItembackFocus == 0 )//改变设置文件
			{
				m_pFileList->RemoveAll ();
				m_pFileList->MakeVisible (ETrue );
				//检索本地文件
				TFileName contentPath(KFbContentsPath);
				AddDrive(contentPath);
				TInt folderId;
				if (iCurrentTabId == 0 )//pingbao
				{
					folderId = 394;
					
				}
				else
				{
					folderId = 395;
				}
				contentPath.AppendFormat (_L("\\data\\%d\\info\\local.xml"), folderId );
				//解析本地内容文件
				if (BaflUtils::FileExists (GetAppUi()->m_fs, contentPath ) )
				{
					m_pXmlHandler->StartParsingL (GetAppUi()->m_fs, contentPath,
							iCurrentTabId );
				}
				//改变左右软件
				m_pSoftKeyBar->SetLeftKeyL (EMainContainerKeySelect, R_SOFT_KEY_SELECT );

			}
		break;
	default:
		return EKeyWasNotConsumed;
	};

	DrawNow ();
	return EKeyWasConsumed;
}


//save to file
void CFlashbox4SettingContainer::SaveConfigL ()
{
	
	BaflUtils::EnsurePathExistsL (GetAppUi()->m_fs, KFbSystemSettingsFile );
	RFileWriteStream wt;
	wt.PushL (); // in on cleanup stack

	if (wt.Replace (GetAppUi()->m_fs, KFbSystemSettingsFile, EFileWrite ) == KErrNone )
	{
		//写屏保
		GetAppUi()->WriteDataToStreamL (wt, GetAppUi()->m_pSettingPingbao );
		//写来电
		GetAppUi()->WriteDataToStreamL (wt, GetAppUi()->m_pSettingLaidian );
		wt.Close ();
	}
	wt.Pop ();
	
	///*通知服务器,读取新设置*/
	
	RFlashBoxServerSession server;
	if (server.Connect () == KErrNone )
	{
		TUint8 code = GetAppUi()->m_pSettingPingbao->m_isOn;
		server.RequestSetting (EFlashBoxServSetSetting,code);
		server.Close ();
	}

	
}
